// pages/choice-shop/index.js
const app = getApp();

const setting = {
  skew: 0,
  rotate: 0,
  showLocation: true,
  showScale: false,
  subKey: 'TXCBZ-KVB6J-OQ7FV-DFXTG-26BB2-ATFFU',
  layerStyle: 1,
  enableZoom: true,
  enableScroll: true,
  enableRotate: true,
  showCompass: false,
  enable3D: false,
  enableOverlooking: true,
  enableSatellite: false,
  enableTraffic: false,
}

// latitude: 42.839480881130164, longitude: 93.50107103058212
// latitude: 42.833426369429226, longitude: 93.54099202283032
const allMarkers = [

  {
    id: 1,
    latitude: 42.839480881130164,
    longitude: 93.50107103058212,
    iconPath: app.data.global_urls.locationIcon,
    callout: {
      content: '昌吉葱花饼店\n（兴业园店）',
      color: '#ff0000',
      fontSize: 14,
      bgColor: 'transparent',
      padding: 0,
      display: 'ALWAYS',
      textAlign: 'center',
      anchorY: 10
    },
  },
  {
    id: 2,
    latitude: 42.833426369429226,
    longitude: 93.54099202283032,
    iconPath: app.data.global_urls.locationIcon,
    callout: {
      content: '昌吉葱花饼店\n（大修厂店）',
      color: '#ff0000',
      fontSize: 14,
      bgColor: 'transparent',
      padding: 0,
      display: 'ALWAYS',
      textAlign: 'center',
      anchorY: 10
    },
  }
]

Component({

  /**
   * 页面的初始数据
   */
  data: {
    setting: setting,
    latitude: 42.839480881130164,
    longitude: 93.50107103058212,
    markers: allMarkers,
    num: 1
  },

  pageLifetimes:{
    /**
     * 生命周期函数--监听页面显示
     */
    show() {
      this.mapCtx = wx.createMapContext('myMap')
    }
  },

  methods: {

    getLocation() {

    },

    moveToMyLocation() {
      this.mapCtx.moveToLocation();
    },

    moveToShop(e) {
      let index = e.currentTarget.dataset.index;
      console.log(allMarkers[index]);

      this.mapCtx.moveToLocation({
        longitude: allMarkers[index].longitude,
        latitude: allMarkers[index].latitude,
      });
    },

    getXYAxis(res) {
      console.log(res)
    },
  }

})